package database

import (
	"sync"

	"mini-admin/pkg/orm"

	"gorm.io/gorm"
)

var (
	once sync.Once
	db   *gorm.DB
)

// New 新建一个DB
func New(c *orm.Config) *gorm.DB {
	once.Do(func() {
		var err error
		db, err = orm.NewPostgreSQL(c)
		if err != nil {
			panic("初始化db错误")
		}
	})

	return db
}
